// translate router.meta.title, be used in breadcrumb sidebar tagsview
import i18n from "@/lang/index";

import type { RouteRecordRaw } from "vue-router";


export function translateRouteTitle(route: RouteRecordRaw) {
  return translateRoute(route.name?.toString(), route.meta?.title);
}

export function translateTagView(tag: TagView) {
  return translateRoute(tag.name, tag.title);
}

export function translateRoute(name: string | undefined, title: string | undefined) {
  let key = name  && name != "" ? name : title;
  //判断是否存在国际化配置，如果没有原生返回
  const hasKey = i18n.global.te("route." + key);
  if (hasKey) {
    const translatedTitle = i18n.global.t("route." + key);
    return translatedTitle;
  }
  return title ? title : name;
}
